package com.artgogo.artgogoerp.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Set;

import com.alibaba.fastjson.JSONObject;

public class JSON2Request {
    public static String parseJSON(JSONObject json) throws UnsupportedEncodingException{
        boolean isFirst = true;
        String context = "";
        json.keySet();
        Set<String> set = json.keySet();
        Iterator<String> iterator = set.iterator();
        while(iterator.hasNext()){
            String key;
            key = iterator.next();
            if(isFirst){
                context = key + "=" + URLEncoder.encode(json.getString(key),"UTF-8");
                isFirst = false;
            } else {
                context += "&" + key + "=" + URLEncoder.encode(json.getString(key),"UTF-8");
            }
        }
        return context;
    }
}
